package com.zyb.warehouse.controller;

import com.zyb.warehouse.common.Result;
import com.zyb.warehouse.dto.Page;
import com.zyb.warehouse.entity.OutStore;
import com.zyb.warehouse.entity.Store;
import com.zyb.warehouse.service.OutStoreService;
import com.zyb.warehouse.service.StoreService;
import com.zyb.warehouse.utils.WarehouseConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:出库表控制层
 */
@RestController
@RequestMapping("/outstore")
public class OutStoreController {

    @Autowired
    private OutStoreService outStoreService;
    @Autowired
    private StoreService storeService;

    /**
     * 添加出库单
     *
     * @param outStore
     * @param token
     * @return
     */
    @PostMapping("/outstore-add")
    public Result addOutStore(@RequestBody OutStore outStore, @RequestHeader(WarehouseConstants.HEADER_TOKEN_NAME) String token) {
        Result result = outStoreService.addOutStore(outStore, token);
        return result;
    }

    /**
     * 获取所有仓库下拉列表
     *
     * @return
     */
    @GetMapping("/store-list")
    public Result getAllStore() {
        List<Store> storeList = storeService.queryAllStore();
        return Result.ok(storeList);
    }

    /**
     * 分页查询出库单
     *
     * @param page
     * @param outStore
     * @return
     */
    @GetMapping("/outstore-page-list")
    public Result page(Page page, OutStore outStore) {
        page = outStoreService.pageOutStore(page, outStore);
        return Result.ok(page);
    }

    /**
     * 确认出库
     *
     * @param outStore
     * @return
     */
    @PutMapping("/outstore-confirm")
    public Result confirmOutStore(@RequestBody OutStore outStore) {
        Result result = outStoreService.confirmOutStore(outStore);
        return result;
    }
}
